$(function() {

	//图片上传显示

	$('.keep').on('click', function() {
		sendForm($(this), 1);
	});
	$('.back').on('click', function() {
		window.history.back()
	});
	$('.car_type').on('click', function() {
		choosecar("{:url('models/index',['op'=>'search'])}")
	});
	$('.car_rental').on('click', function() {
		choosecar("{:url('rent/index',['op'=>'search'])}")
	});
	//选择品牌
	$('.brand select').on('change',function(){
		var brandid=$(this).val();
		var brand = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:brandid
			},
			success:function(res){
				console.log(res);
				  layer.close(brand);
				
					$('.model select').html(res);
				
				
			}
		});
	})
	$('.model select').on('change',function(){
		var model = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var modelid=$(this).val();
		console.log(modelid)
		if(modelid){
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:modelid
			},
			success:function(res){
				console.log(res)
				 $('.series select').html(res)
			}
		});
		}else{
			$('.series select').html('')
		}
		layer.close(model);
	})
	$('.buy_date').on('change',function(){
		var newdata=new Date()
		var buydata=new Date($(this).val())
		var year=Math.ceil((newdata-buydata)/1000/3600/24/365)
		$('.car_age').val(year)
	})

	
})